1 #include<iostream>
2 #include<fstream>
3 #include<cctype>
4 #include<iomanip>
5 using namespace std;
6
7
8
9 class account
10 {
11 int acno;
12 char name[50];
13 int deposit;
14 char type;
15 public:
16 void create_account();
17 void show_account() const;
18 void modify();
19 void dep(int);
20 void draw(int);
21 void report() const;
22 int retacno() const;
23 int retdeposit() const;
24 char rettype() const;
25 };
26
27 void account::create_account()
28 {
29 system("CLS");
30 cout<<"\n\t\t\tEnter the Account No. : ";
31 cin>>acno;
32 cout<<"\n\n\t\t\tEnter the Name of the Account holder : ";
33 cin.ignore();
34 cin.getline(name,50);
35 cout<<"\n\t\t\tEnter Type of the Account (C/S) : ";
36 cin>>type;
37 type=toupper(type);
38 cout<<"\n\t\t\tEnter The Initial amount : ";
39 cin>>deposit;
40 cout<<"\n\n\t\t\tAccount Created..";
41 }
42
43 void account::show_account() const
44 {
45 cout<<"\n\t\t\tAccount No. : "<<acno;
46 cout<<"\n\t\t\tAccount Holder Name : ";
47 cout<<name;
48 cout<<"\n\t\t\tType of Account : "<<type;
49 cout<<"\n\t\t\tBalance amount : "<<deposit;
50 }
51
52
53 void account::modify()
54 {
55 cout<<"\n\t\t\tAccount No. : "<<acno;
56 cout<<"\n\t\t\tModify Account Holder Name : ";
57 cin.ignore();
58 cin.getline(name,50);
59 cout<<"\n\t\t\tModify Type of Account : ";
60 cin>>type;
61 type=toupper(type);
62 cout<<"\n\t\t\tModify Balance amount : ";
63 cin>>deposit;
64 }
65
66
67 void account::dep(int x)
68 {
69 deposit+=x;
70 }
71
72 void account::draw(int x)
73 {
74 deposit-=x;
75 }
76
77 void account::report() const
78 {
79 cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl;
80 }
81
82 int account::retacno() const
83 {
84 return acno;
85 }
86
87 int account::retdeposit() const
88 {
89 return deposit;
90 }
91
92 char account::rettype() const
93 {
94 return type;
95 }
96
97
98
99 void write_account();
100 void display_sp(int);
101 void modify_account(int);
102 void delete_account(int);
103 void display_all();
104 void deposit_withdraw(int, int);
105
106 int main()
107 {
108 char ch;
109 int num;
110 do
111 {
112 system("CLS");
113 cout<<"\n\n\t\t\t\t======================\n";
114 cout<<"\t\t\t\tBANK MANAGEMENT SYSTEM";
115 cout<<"\n\t\t\t\t======================\n";
116
117 cout<<"\t\t\t\t ::MAIN MENU::\n";
118 cout<<"\n\t\t\t\t1. NEW ACCOUNT";
119 cout<<"\n\t\t\t\t2. DEPOSIT AMOUNT";
120 cout<<"\n\t\t\t\t3. WITHDRAW AMOUNT";
121 cout<<"\n\t\t\t\t4. BALANCE ENQUIRY";
122 cout<<"\n\t\t\t\t5. ALL ACCOUNT HOLDER LIST";
123 cout<<"\n\t\t\t\t6. CLOSE AN ACCOUNT";
124 cout<<"\n\t\t\t\t7. MODIFY AN ACCOUNT";
125 cout<<"\n\t\t\t\t8. EXIT";
126 cout<<"\n\n\t\t\t\tSelect Your Option (1-8): ";
127 cin>>ch;
128
129 switch(ch)
130 {
131 case '1':
132 write_account();
133 break;
134 case '2':
135 system("CLS");
136 cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num;
137 deposit_withdraw(num, 1);
138 break;
139 case '3':
140 system("CLS");
141 cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num;
142 deposit_withdraw(num, 2);
143 break;
144 case '4':
145 system("CLS");
146 cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num;
147 display_sp(num);
148 break;
149 case '5':
150 display_all();
151 break;
152 case '6':
153 system("CLS");
154 cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num;
155 delete_account(num);
156 break;
157 case '7':
158 system("CLS");
159 cout<<"\n\n\t\t\tEnter The account No. : "; cin>>num;
160 modify_account(num);
161 break;
162 case '8':
163 system("CLS");
164 cout<<"\n\n\t\t\tBrought To You By code-projects.org";
165 break;
166 default :cout<<"\a";
167 }
168 cin.ignore();
169 cin.get();
170 }while(ch!='8');
171 return 0;
172 }
173
174
175 void write_account()
176 {
177 account ac;
178 ofstream outFile;
179 outFile.open("account.dat",ios::binary|ios::app);
180 ac.create_account();
181 outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
182 outFile.close();
183 }
184
185 void display_sp(int n)
186 {
187 account ac;
188 bool flag=false;
189 ifstream inFile;
190 inFile.open("account.dat",ios::binary);
191 if(!inFile)
192 {
193 cout<<"File could not be open !! Press any Key...";
194 return;
195 }
196 cout<<"\n\t\t\tBALANCE DETAILS\n";
197 while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
198 {
199 if(ac.retacno()==n)
200 {
201 ac.show_account();
202 flag=true;
203 }
204 }
205 inFile.close();
206 if(flag==false)
207 cout<<"\n\n\t\t\tAccount number does not exist";
208 }
209
210
211
212 void modify_account(int n)
213 {
214 bool found=false;
215 account ac;
216 fstream File;
217 File.open("account.dat",ios::binary|ios::in|ios::out);
218 if(!File)
219 {
220 cout<<"File could not be open !! Press any Key...";
221 return;
222 }
223 while(!File.eof() && found==false)
224 {
225 File.read(reinterpret_cast<char *> (&ac), sizeof(account));
226 if(ac.retacno()==n)
227 {
228 ac.show_account();
229 cout<<"\n\n\t\t\tEnter The New Details of account"<<endl;
230 ac.modify();
231 int pos=(-1)*static_cast<int>(sizeof(account));
232 File.seekp(pos,ios::cur); //fncallat1353
233 File.write(reinterpret_cast<char *> (&ac), sizeof(account));
234 cout<<"\n\n\t\t\tRecord Updated";
235 found=true;
236 }
237 }
238 File.close();
239 if(found==false)
240 cout<<"\n\n\t\t\tRecord Not Found ";
241 }
242
243
244
245 void delete_account(int n)
246 {
247 account ac;
248 ifstream inFile;
249 ofstream outFile;
250 inFile.open("account.dat",ios::binary);
251 if(!inFile)
252 {
253 cout<<"File could not be open !! Press any Key...";
254 return;
255 }
256 outFile.open("Temp.dat",ios::binary);
257 inFile.seekg(0,ios::beg);
258 while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
259 {
260 if(ac.retacno()!=n)
261 {
262 outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
263 }
264 }
265 inFile.close();
266 outFile.close();
267 remove("account.dat");
268 rename("Temp.dat","account.dat");
269 cout<<"\n\nRecord Deleted ..";
270 }
271
272
273 void display_all()
274 {
275 system("CLS");
276 account ac;
277 ifstream inFile;
278 inFile.open("account.dat",ios::binary);
279 if(!inFile)
280 {
281 cout<<"File could not be open !! Press any Key...";
282 return;
283 }
284 cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
285 cout<<"====================================================\n";
286 cout<<"A/c no. NAME Type Balance\n";
287 cout<<"====================================================\n";
288 while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
289 {
290 ac.report();
291 }
292 inFile.close();
293 }
294
295
296 void deposit_withdraw(int n, int option)
297 {
298 int amt;
299 bool found=false;
300 account ac;
301 fstream File;
302 File.open("account.dat", ios::binary|ios::in|ios::out);
303 if(!File)
304 {
305 cout<<"File could not be open !! Press any Key...";
306 return;
307 }
308 while(!File.eof() && found==false)
309 {
310 File.read(reinterpret_cast<char *> (&ac), sizeof(account));
311 if(ac.retacno()==n)
312 {
313 ac.show_account();
314 if(option==1)
315 {
316 cout<<"\n\n\t\t\tTO DEPOSITSS AMOUNT";
317 cout<<"\n\n\t\t\tEnter The amount to be deposited: ";
318 cin>>amt;
319 ac.dep(amt);
320 }
321 if(option==2)
322 {
323 cout<<"\n\n\t\t\tTO WITHDRAW AMOUNT";
324 cout<<"\n\n\t\t\tEnter The amount to be withdraw: ";
325 cin>>amt;
326 int bal=ac.retdeposit()-amt;
327 if(bal<0)
328 cout<<"Insufficience balance";
329 else
330 ac.draw(amt);
331 }
332 int pos=(-1)*static_cast<int>(sizeof(ac));
333 File.seekp(pos,ios::cur);//fn1353
334 File.write(reinterpret_cast<char *> (&ac), sizeof(account));
335 cout<<"\n\n\t\t\tRecord Updated";
336 found=true;
337 }
338 }
339 File.close();
340 if(found==false)
341 cout<<"\n\n\t\t\tRecord Not Found ";
342 }